package com.aqie.arithmetic.sort;

public class InsertSort extends SortTest {
    @Override
    public void sort(Comparable[] a) {
        int N = a.length;
        for (int i = 1; i < N; i++){
            // 将 a[i] 插入到 a[i-1] a[i-2] ... a[0]
            for (int j = i; j > 0 && less(a[j], a[j - 1]); j--){
                exch(a,j,j-1);
            }
        }
    }

    public static void main(String[] args) {
        new InsertSort().process(5);
    }
}
